package com.sz.test.common;

import lombok.Data;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
@Data
public class R {

   private Integer code;

   private String msg;

   private Map<String,Object> dataMap=new HashMap<String, Object>();

   private R(){}

   public static R ok(String msg){
      R r = new R();
      r.setCode(200);
      r.setMsg(msg);
      return r;
   }

   public static R error(String msg){
      R r = new R();
      r.setCode(500);
      r.setMsg(msg);
      return r;
   }

   public static R error(Integer code,String msg){
      R r = new R();
      r.setCode(code);
      r.setMsg(msg);
      return r;
   }
   public R data(String key,Object val){
     this.dataMap.put(key,val);
     return this;
   }
   public R data(Map<String,Object> maps){
      Set<Map.Entry<String, Object>> entries = maps.entrySet();
      Iterator<Map.Entry<String, Object>> iterator = entries.iterator();
      while (iterator.hasNext()){
         Map.Entry<String, Object> next = iterator.next();
         String key = next.getKey();
         Object value = next.getValue();
         this.dataMap.put(key,value);
      }
      return this;
   }
}
